package xyz.fuqufyb.aec.controller;

import com.spingcloud.travel.common.JsonResult;
import com.springcloud.travel.entity.Info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import xyz.fuqufyb.aec.data.TableResult;
import xyz.fuqufyb.aec.feign.InfoFeign.InfoFeign;


@RestController
@RequestMapping("/sys/info")
public class SysInfoController {
    @Autowired
    private InfoFeign infoFeign;

    @RequestMapping("/table")
    public TableResult table(Integer page, Integer limit) {
        try {
            TableResult table = infoFeign.getTable(page, limit);
            return table;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @PostMapping("/addInfo")
    public JsonResult add(Info info) {
        try {
            boolean insert = infoFeign.addInfo(info);

            if (insert) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.getJsonResultByFail();
    }

    @RequestMapping("/del")
    public JsonResult delInfo(@RequestParam(value = "ids")String[] ids) {
        try {
            boolean insert = infoFeign.delInfo(ids);
            if (insert) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.getJsonResultByFail();
    }

    @RequestMapping("/update")
    public JsonResult updateInfo(Info info) {
        try {
            boolean insert = infoFeign.updateInfo(info);
            System.out.println("SysInfoController.updateInfo");
            if (insert) {
                return JsonResult.getJsonResultBySuccess();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonResult.getJsonResultByFail();

    }
}
